package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.CapaMoneyConfigBean;
import com.koron.css2.clientCenter.mapper.ChangeUserMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.HashMap;
import java.util.Map;

public class UserCapaMoneyChange implements ServerInterface {
	
	private static Logger logger = LogManager.getLogger(UserCapaMoneyChange.class);

	@SuppressWarnings("rawtypes")
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<Map> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", Map.class);
		try {
			CapaMoneyConfigBean bean = JsonUtils.objectToPojo(req.getData(), CapaMoneyConfigBean.class);
			ChangeUserMapper mapper = factory.getMapper(ChangeUserMapper.class);
			HashMap<String, Object> map = mapper.getCapaMoney(bean);
			info.setData(map);
			return info;
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("获取容量水费失败");
			logger.error(e.getMessage(), e);
			return info;
		}
	}
}
